package work3_9;

import java.util.*;

public class Demo4 {
    /**
     * Map的使用方法
     */
    public static void main(String[] args) {
        Map map=new HashMap();
        map.put(1,"a");
        map.put(2,"b");
        map.put(3,"c");
        map.put(4,"null");

        //迭代map集合：entrySet,keySet,values
        /**
         *  1、entrySet
         */

//              Set set=map.entrySet();
//              //遍历set集合
//              for (Object obj:set){
//                  if(obj instanceof Map.Entry entry){
//                     System.out.println(entry.getKey() + ", " + entry.getValue());
//                  }
//              }
        /**
         *   2、keySet
         */
        Set set=new HashSet();
//        for (Object key:set) {
//            System.out.println(key+","+map.get(key));
//        }
//        System.out.println(map);
        //用接口实现
//        Iterator iterator= set.iterator();
//         while(iterator.hasNext()){
//             //每一次iterator.next()接收下一个元素
//           Object key=iterator.next();
//             System.out.println(key+","+map.get(key));
//        }
        /**
         * 3、values
         */
        Collection values=map.values();
        for (Object value:values) {
            System.out.println(value);
        }
        Iterator iterator= values.iterator();
        while(iterator.hasNext()){
            Object value=iterator.next();
            System.out.println(value);
        }
    }
}